def originalData = page.getData()

if (!originalData || originalData.isEmpty()) {
    return []
}

def totals = [
    field1: "总计",
    field2: originalData.sum { it.total_inspections.toInteger() },
    field3: originalData.sum { it.confirmed_inspections },
    field4: originalData.sum { it.unconfirmed_inspections },
    beRaising: true,
    trendValue: 0,
    index_96pica: 0
]

// Transform individual items
def transformed = originalData.collect { item ->
    [
        field1: item.law_subject_name,
    field2: item.total_inspections.toInteger(),
    field3: item.confirmed_inspections,
    field4: item.unconfirmed_inspections,
    beRaising: true,
    trendValue: 0,
    index_96pica: item.law_subject_id
]
}

def result = []
result.add(totals)
result.addAll(transformed)

return result
